package com.itboye.ihomebank.myzhujia;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.itboye.ihomebank.R;
import com.itboye.ihomebank.base.BaseOtherActivity;
import com.itboye.ihomebank.support.commonadapter.MutiplyCommonAdapter;
import com.itboye.ihomebank.support.commonadapter.ViewHolder;
import com.itboye.ihomebank.util.CameraPopupWindow;
import com.itboye.ihomebank.util.XImageLoader;

/**
 * 住家维修（填写内容）
 * 
 */
public class ActivityZhuJiaRepair extends BaseOtherActivity {
	TextView add_shap_title_tv;
	ImageView close_icon;

	RelativeLayout zhujia_repair_layout01, zhujia_repair_layout02,
			zhujia_repair_layout03, zhujia_repair_layout04;
	EditText zhujia_repair_name, zhujia_repair_phone, zhujia_repair_leixing,
			zhujia_repair_xx;
	GridView zhujia_repair_img;
	TextView zhujia_repair_ok;// 下一步
	private ArrayList<String> list;
	protected CameraPopupWindow cameraPopupWindow;

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.close_icon:
			finish();
			break;
		case R.id.zhujia_repair_layout01:// 报修人姓名

			break;
		case R.id.zhujia_repair_layout02:// 手机号

			break;
		case R.id.zhujia_repair_layout03:// 选择报修类型

			break;
		case R.id.zhujia_repair_layout04:// 详细信息

			break;
		case R.id.zhujia_repair_ok:// 完成

			break;
		case R.id.pick_image:
			break;
		case R.id.open_camera:
			break;
		case R.id.camera_cancel_tv:
			if (cameraPopupWindow != null) {
				cameraPopupWindow.dismiss();
			}
			break;
		default:
			break;
		}
	}

	@Override
	protected int layout_id() {
		return R.layout.activity_zhujia_repair;
	}

	@Override
	protected void onInitController() {
		// TODO Auto-generated method stub

	}

	@Override
	protected void onInit() {
		add_shap_title_tv.setText("住家维修");
		list = new ArrayList<String>();
		ImageAdpater adapter = new ImageAdpater(this, list,
				R.layout.item_fabiao_tiezi_image_select);
		zhujia_repair_img.setAdapter(adapter);
		zhujia_repair_img.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				// TODO Auto-generated method stub
				if (position == list.size()) {
					cameraPopupWindow = new CameraPopupWindow(
							ActivityZhuJiaRepair.this,
							ActivityZhuJiaRepair.this);
					cameraPopupWindow.showAtLocation(view, Gravity.BOTTOM
							| Gravity.CENTER_HORIZONTAL, 0, 0);
				}
			}
		});
	}

	@Override
	protected void onActivityResult(int arg0, int arg1, Intent arg2) {
		// TODO Auto-generated method stub
		super.onActivityResult(arg0, arg1, arg2);
	}

	@Override
	protected void onReadIntent(Bundle bundle) {
		// TODO Auto-generated method stub

	}

	class ImageAdpater extends MutiplyCommonAdapter<String> {

		List<String> datas;

		public ImageAdpater(Context context, List<String> datas,
				int... layoutId) {
			super(context, datas, layoutId);
			// TODO Auto-generated constructor stub
			this.datas = datas;
		}

		@Override
		public int getItemViewType(int position) {
			// TODO Auto-generated method stub
			return 0;
		}

		@Override
		public void getItemPosition(int position) {
			// TODO Auto-generated method stub

		}

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return datas.size() + 1;
		}

		@Override
		public void convert(ViewHolder holder, String t, int type, int position) {
			// TODO Auto-generated method stub
			if (position == datas.size()) {
				holder.setImageResource(R.id.img,
						R.drawable.icon_addpic_unfocused);
				if (position == 9) {
					holder.setVisible(R.id.img, false);
				}
			} else {
				holder.setVisible(R.id.img, true);
				XImageLoader.load("file://" + t,
						(ImageView) holder.getView(R.id.img));
			}
		}

	}

}
